package com.new24hour;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ExrAdap extends BaseAdapter {

	private List<Store> storeList;
	private int loc;
	private int cat;
	private LayoutInflater inflater;
	Store store;
	private Context context;


	public ExrAdap(Context context, ArrayList<Store> arr) {
		this.context = context;
		this.storeList = arr;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		
		int size = 0;
		int fullSize = storeList.size();

		Store temp;
		for (int i = 0; i < fullSize; i++) {
			/*loc = storeList.get(i).getlocation();
			cat = storeList.get(i).getcategory();*/
			loc = 1;
			cat = 0;
			temp = storeList.get(i);
			if (temp.location == loc && temp.category == cat) {
				size++;
			}
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		Store temp;
		int itemIndex = 0;
		int fullSize = storeList.size();

		for (int i = 0; i < fullSize; i++) {
			loc = 1;
			cat = 0;
			temp = storeList.get(i);
			if (temp.location == loc && temp.category == cat) {
				if (position == itemIndex) {
					return temp;
				}
				itemIndex++;
				}
			}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.listview, parent, false);
		}

		TextView name = (TextView) convertView.findViewById(R.id.storeName);
		name.setText(storeList.get(position).getStoreName());

		return convertView;
	}
}
